package thread;

import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Thread t1 = new Thread(){
            public void run(){
                synchronized (list) {
                    for (int i = 0; i < 10000000; i++) {
                        list.add(i);
                    }
                }
            }
        };

        Thread t2 = new Thread(){
            public void run(){
                synchronized (list){
                for (int i = 0; i < 10000000; i++) {
                    list.add(i);
                }
            }
            }
        };

        t1.start();
        t2.start();

        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(list.size());
    }

}
